import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) throws Exception {
        Class<?> cl = Class.forName("Student");

        Constructor<?> constructor = cl.getDeclaredConstructor();
        constructor.setAccessible(true);
        Object stu = constructor.newInstance();

        Method studyMethod = cl.getDeclaredMethod("study", String.class);
        studyMethod.setAccessible(true);
        studyMethod.invoke(stu, "java reflection");

        Field attribute_name = cl.getDeclaredField("name");
        attribute_name.setAccessible(true);
        attribute_name.set(stu, "Tom");
        Field attribute_age = cl.getDeclaredField("age");
        attribute_age.setAccessible(true);
        attribute_age.set(stu, 16);

        // private method
        studyMethod.invoke(stu, "java reflection");
    }
}
